{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Chipping directory A\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/root/miniconda3/envs/torchenv/lib/python3.11/site-packages/image_bbox_slicer/helpers.py:113: UserWarning: Destination /workspace/storage/data/levircd-train-chipped/A directory does not exist so creating it now\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Obtained 7120 image slices!\n",
      "Chipping directory B\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/root/miniconda3/envs/torchenv/lib/python3.11/site-packages/image_bbox_slicer/helpers.py:113: UserWarning: Destination /workspace/storage/data/levircd-train-chipped/B directory does not exist so creating it now\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Obtained 7120 image slices!\n",
      "Chipping directory label\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/root/miniconda3/envs/torchenv/lib/python3.11/site-packages/image_bbox_slicer/helpers.py:113: UserWarning: Destination /workspace/storage/data/levircd-train-chipped/label directory does not exist so creating it now\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Obtained 7120 image slices!\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from pathlib import Path\n",
    "from tqdm import tqdm\n",
    "from image_bbox_slicer import Slicer\n",
    "\n",
    "\n",
    "directories = [\"A\", \"B\", \"label\"]\n",
    "root = \"/workspace/storage/data/levircd-train/\"\n",
    "output = \"/workspace/storage/data/levircd-train-chipped/\"\n",
    "\n",
    "for directory in directories:\n",
    "    print(f\"Chipping directory {directory}\")\n",
    "    slicer = Slicer()\n",
    "    src = os.path.join(root, directory)\n",
    "    dst = os.path.join(output, directory)\n",
    "    slicer.config_image_dirs(img_src=src, img_dst=dst)\n",
    "    slicer.slice_images_by_size(tile_size=(256, 256), tile_overlap=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 7120/7120 [00:00<00:00, 41922.67it/s]\n",
      "100%|██████████| 7120/7120 [00:00<00:00, 42265.97it/s]\n",
      "100%|██████████| 7120/7120 [00:00<00:00, 39905.19it/s]\n"
     ]
    }
   ],
   "source": [
    "root = Path(\"/workspace/storage/data/levircd-train-chipped/\")\n",
    "\n",
    "for directory in directories:\n",
    "    path = root / directory\n",
    "    files = list(path.glob(\"*.png\"))\n",
    "    for f in tqdm(files):\n",
    "        dst = path / f\"train_{f.name}\"\n",
    "        _ = f.rename(dst)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torchenv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
